import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_bmfmap_example/models/marketinfomodel.dart';
import 'package:provider/provider.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

class buyCarValue extends StatefulWidget {
  buyCarValue(
      {Key key,
      this.Selection,
      this.name,
      this.intro,
      this.money,
      this.commodityNumber,
      this.invoicing,
      this.imgurl1,
      this.id,})
      : super(key: key);
  int id;
  bool Selection;
  String name;
  String intro;
  double money;
  int commodityNumber;
  String imgurl1;
  ValueChanged<int> invoicing;
  @override
  _buyCarValueState createState() => _buyCarValueState();
}

class _buyCarValueState extends State<buyCarValue> {

  @override
  initState() {
    // TODO: implement initState
    super.initState();
    // 页面加载时调用 用来开始时访问数据库
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top:8.0,bottom: 8,left:24,right:24),
      child: Slidable(
        actionPane: SlidableBehindActionPane(), //滑出选项的面板 动画
        secondaryActions: <Widget>[
          //右侧按钮列表
          // IconSlideAction(
          //   caption: 'More',
          //   color: Colors.black45,
          //   icon: Icons.more_horiz,
          //   // onTap: () => _showSnackBar('More'),
          // ),
          ClipRRect(
            borderRadius: BorderRadius.only(topRight: Radius.circular(10),bottomRight: Radius.circular(10)),
            child: IconSlideAction(
              caption: 'Delete',
              color: Colors.red,
              icon: Icons.delete,
              closeOnTap: true,
              onTap: () {
                var newList = context
                    .read<Shoppingcatmodel>()
                    .deleteshopcart(widget.id);
              },
            ),
          ),
        ],

        // actionExtentRatio: 0.25,
        child: Container(
          padding: EdgeInsets.all(8),
          decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(10),
              boxShadow: [
                BoxShadow(color: Colors.black26, blurRadius: 8, spreadRadius: 0)
              ]),
          // margin: EdgeInsets.fromLTRB(16, 10, 16, 10),
          // padding: EdgeInsets.fromLTRB(16, 8, 16, 8),
          child: Row(
            children: [
              Container(
                height: 24,
                width: 24,
                child: Checkbox(
                  shape: CircleBorder(), //这里就是实现圆形的设置
                  visualDensity: VisualDensity.comfortable,
                  value: widget.Selection,
                  onChanged: (bool value) {
                    changeselect();
                    // setState(() {
                    //   widget.Selection = value;
                    // });
                  },
                ),
              ),
              Container(
                padding: EdgeInsets.only(left: 8, top: 16, right: 16, bottom: 16),
                child: Image.network(
                  // 'assets/images/common/shopping_images/正确.png',
                  widget.imgurl1,
                  width: 88,
                  height: 88,
                ),
              ),
              Expanded(
                flex: 1,
                child: Container(
                  // height: 80,
                  // margin: EdgeInsets.fromLTRB(0, 8, 8, 8),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            widget.name,
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 18,
                                color: Colors.blueGrey[700]),
                          ),
                          Text(
                            widget.intro,
                            style: TextStyle(
                              color: Colors.grey[500],
                              fontSize: 14,
                            ),
                            maxLines: 2,
                          ),
                          Row(
                            children: [
                              Text(
                                '${widget.money}',
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontSize: 16,
                                    color: Colors.blueGrey[700]),
                              ),
                              Spacer(),
                              Container(
                                child: Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceAround,
                                  children: [
                                    GestureDetector(
                                      onTap: _minusNum,
                                      child: Container(
                                        decoration: BoxDecoration(
                                            color: Colors.grey[50],
                                            borderRadius:
                                                BorderRadius.circular(2),
                                            boxShadow: [
                                              BoxShadow(
                                                  color: Colors.grey[400],
                                                  blurRadius: 4,
                                                  spreadRadius: 0)
                                            ]),
                                        child: Icon(Icons.remove),
                                      ),
                                    ),
                                    Padding(
                                      padding: const EdgeInsets.all(8.0),
                                      child: Text('${widget.commodityNumber}'),
                                    ),
                                    GestureDetector(
                                      onTap: _addNum,
                                      child: Container(
                                        // padding: EdgeInsets.all(3),
                                        decoration: BoxDecoration(
                                            color: Colors.grey[50],
                                            borderRadius:
                                                BorderRadius.circular(2),
                                            boxShadow: [
                                              BoxShadow(
                                                  color: Colors.grey[400],
                                                  blurRadius: 4,
                                                  spreadRadius: 0)
                                            ]),
                                        child: Icon(Icons.add),
                                      ),
                                    ),
                                  ],
                                ),
                              )
                            ],
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

  void _minusNum() {
    context.read<Shoppingcatmodel>().removeshopcartitemnum(widget.id);
  }

  void changeselect() {
    context.read<Shoppingcatmodel>().changeselect(widget.id);
  }

  void _addNum() {
    context.read<Shoppingcatmodel>().addshopcartitemnum(widget.id,1);
  }

}
